# load data
datos <- read.table("ministerios.time", header=T) # ns ip syn_time connect_time
graf <- "scan_times.png"

host = datos$ns
syn = datos$syn_time
con = datos$connect_time

len = length(host)
syn_prom = sum(syn) / len
con_prom = sum(con) / len

print(syn_prom)
print(con_prom)

print(datos)

# plot
png(filename=graf, width=1024, height=768, bg="white")

par(mar=c(10,5,5,2))  # manipulate margins (bottom,left,top,right)

g_range <- range(0, syn, con)  # Calculate range from 0 to max value

# Graph using y-axis that g_ranges 
# Turn off axes and annotations (axis labels) so we can specify them ourself
plot(rep(syn_prom, len), type="l", col="grey40", ylim=g_range, axes=FALSE, ann=FALSE)
lines(rep(con_prom, len), type="l", col="grey70") # plot con_prom times

#~ print(rep(syn_prom, 10))

# Make y-axis with horizontal labels that display ticks at 
# every 100 marks. 100*0:g_range[2] is equivalent to c(0,100,200,...,1000).
axis(2, las=1, at=100*0:g_range[2])

# Make x-axis tick marks without labels
axis(1, lab=F, at=1:len)

# Plot x-axis labels at default tick marks with labels at 45 degree angle
text(1:len, par("usr")[3] - 60, srt=45, adj=1, labels=host, xpd=T, cex=1.2)

box() # box around plot

lines(syn, type="b", pch=21, lty=1, col="forestgreen") # plot syn times
lines(con, type="b", pch=21, lty=1, col="blue")     # plot connect times

title(main="Mediciones de Connect Scan vs. SYN Scan por host",
      xlab="", ylab="Time (seg)")      # titles

# legend: x-pos, y-pos, names, ...
legend(9, 1330, c("SYN Prom","Connect Prom","SYN Scan","Connect Scan"), cex=1.2,
        col=c("grey40", "grey70","forestgreen","blue"),
        pch=c(45,45,21,21), lty=c(1,1,0,0))

dev.off()
